<template>
  <div class="cart py-container">
    <!--主内容-->
    <div class="checkout py-container pay">
      <div class="checkout-tit">
        <h4 class="fl tit-txt">
          <span class="success-icon"></span>
          <span class="success-info">订单提交成功，请您及时付款！订单号：{{payObj.out_trade_no}}</span>
        </h4>
        <span class="fr">
          <em class="sui-lead">应付金额：</em>
          <em class="orange money">￥{{payObj.total_fee}}</em>
        </span>
        <!-- <p>User ID: {{ $route.params.id }}</p> -->
        <div class="clearfix"></div>
      </div>
      <div class="checkout-steps">
        <div class="fl weixin">微信支付</div>
        <div class="fl sao">
          <p class="red">请使用微信扫一扫。</p>
          <div class="fl code">
            <qriously :value="payObj.code_url" :size="338"/>
            <div class="saosao">
              <p>请使用微信扫一扫</p>
              <p>扫描二维码支付</p>
            </div>
          </div>
        </div>
        <div class="clearfix"></div>
        <!-- <p><a href="pay.html" target="_blank">> 其他支付方式</a></p> -->
      </div>
    </div>
  </div>
</template>
<script>
import pay from "@/api/orders";

export default {
  //每隔5秒钟，查询一下订单支付状态
  //需要创建定时器setIntervar(()=>{},5000)
  data() {
    return {
      timer1: "",
      payObj: {},
      orderNo: ""
    };
  },
  mounted() {
    const id = this.$route.params.id
    this.pay(id);
    this.timer1 = setInterval(() => {
      this.queryPayStatusInfo(id);
    }, 5000);
  },
  methods: {
    pay(id){
      pay.createNative(id).then(response => {
        this.payObj = response.data;
      });
    },
    queryPayStatusInfo(id) {
      pay.queryPayStatus(id).then(response => {
        console.log(response)
        if (response.code === 20000) {
          //如果支付成功，清除定时器
          clearInterval(this.timer1);
          //提示成功
          this.$message({
            type: "success",
            message: "支付成功!"
          });
          //跳转到订单页面
          this.$router.push({path:`/orders/list`})
        }
      });
    }
  }
};
</script>
